package com.wandian.texas.dao.Impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import com.wandian.texas.GameData;
import com.wandian.texas.dao.ServerListDao;
import com.wandian.texas.db.BaseDao;
import com.wandian.texas.db.DBMgr;
import com.wandian.texas.entity.ServerListEntity;
import com.wandian.util.Log;

/**
 * @author long
 * @Create 2012-10-19 下午2:47:12
 * @QQ 108232706
 * @version 1.0
 * @description ServerListDaoImpl
 */
public class ServerListDaoImpl extends BaseDao implements ServerListDao {

	public ServerListDaoImpl(DBMgr _dbMgr) {
		super(_dbMgr);
	}

	public ServerListEntity find(int id) {
		String sqlText = "select * from t_ServerList WHERE  ServerId=" + id;
		ServerListEntity entity = null;
		ResultSet rs = null;
		Statement stmt = null;
		Connection conn = openConn();
		try {
			stmt = this.getStatement();
			rs = stmt.executeQuery(sqlText);
			if (rs != null && rs.last()) {
				entity = new ServerListEntity();
				entity.ServerId = id;
				entity.ServerIndex = rs.getInt("ServerIndex");
				entity.ServerName = rs.getString("ServerName");
				entity.ServerState = rs.getInt("ServerState");
				entity.RoomCount = rs.getInt("RoomCount");
				entity.ServerIp = rs.getString("ServerName");
				entity.Port = rs.getInt("Port");
				entity.SessionMaxCount = rs.getInt("SessionMaxCount");
				entity.SessionWarnCount = rs.getInt("SessionWarnCount");
				entity.CmdThreadCount = rs.getInt("CmdThreadCount");
				entity.CmdQueueCount = rs.getInt("CmdQueueCount");
				entity.CurrentSessionCount = rs.getInt("CurrentSessionCount");
				entity.State = rs.getInt("State");
				entity.Description = rs.getString("Description");
				entity.CreateDate = rs.getTimestamp("CreateDate");
				// entity.SystemTotalWin = rs.getInt("SystemTotalWin");
				GameData.setSystemTotalWin(rs.getFloat("NotSendMoney"));
				Log.info("未能与中心服连接盈利累计至:" + GameData.getSystemTotalWin());
			}
		} catch (Exception e) {
			Log.error(e);
		} finally {
			closeConn(stmt, rs);
		}
		return entity;
	}

	public ServerListEntity[] findList(String strWhere) {
		return null;
	}

	public boolean add(ServerListEntity entity) {
		return false;
	}

	public boolean delete(int id) {
		return false;
	}

	public boolean delete(String strWhere) {
		return false;
	}

	@Override
	protected Connection openConn() {
		return this.dbMgr.openConn();
	}

}
